package com.company;

import java.util.*;

public class Task3 {
    public static void main(String[] args) {
        //todo 3. 如何在字符串中找到第一个不重复的字符(使用Java集合框架)
        // 字符串： yellow
        Set<Character> repeating = new HashSet<Character>();
        List<Character> nonRepeating = new ArrayList<Character>();
        String str = "yellow";
        for (int i = 0; i < str.length(); i++) {
            char letter = str.charAt(i);//依次获得字符串中的每个字符
            if (repeating.contains(letter)) {
                continue;
            }
            if (nonRepeating.contains(letter)) {
                nonRepeating.remove((Character) letter);
                repeating.add(letter);
            } else {
                nonRepeating.add(letter);
            }
            System.out.println(nonRepeating);

        }
        System.out.println("字符串中第一个非重复的字符为:    "+ nonRepeating.get(0));
    }

}
